package net.wanho.service.impl;

import net.wanho.po.Dept;
import net.wanho.mapper.DeptMapper;
import net.wanho.service.DeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * <p>
 * 部门表 服务实现类
 * </p>
 *
 * @author 汤小洋
 * @since 2023-12-26
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

   /**
    *  部门表 按查询分页查询
    */
    @Override
    public IPage<Dept> findPage(int pageNum, int pageSize,Dept dept) {
        QueryWrapper<Dept> wrapper = getDeptQueryWrapper(dept);
        IPage<Dept> page = new Page<>(pageNum, pageSize);
        page = this.page(page, wrapper);
        return page;
    }

   /**
    *  部门表 查询条件
    */
     private QueryWrapper<Dept> getDeptQueryWrapper(Dept dept) {
        QueryWrapper<Dept> wrapper = new QueryWrapper<Dept>();
        // 编号
        wrapper.lambda().eq(!ObjectUtils.isEmpty(dept.getId()),Dept::getId, dept.getId());
        // 部门名称
        wrapper.lambda().eq(!ObjectUtils.isEmpty(dept.getName()),Dept::getName, dept.getName());
        return wrapper;
    }
}
